package manager.Frame.admin;

import manager.Frame.LoginPanel;
import manager.Frame.MainFrame;
import manager.util.SystemConstants;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class AdminPanel extends JPanel {
    private  static JDesktopPane contentPanel=new JDesktopPane();
    public AdminPanel(){
        this.setBounds(0,0, SystemConstants.FRAME_WIDTH,SystemConstants.FRAME_HEIGHT);
        this.setLayout(new BorderLayout());
        this.setVisible(true);
        JMenuBar menuBar=new JMenuBar();
        menuBar.setBounds(0,0,SystemConstants.FRAME_WIDTH,50);
        this.add(menuBar,BorderLayout.NORTH);
        contentPanel.removeAll();
        contentPanel.repaint();
        this.add(contentPanel,BorderLayout.CENTER);
        JMenu parentMenu=new JMenu("xx管理");
        JMenu adminMenu=new JMenu("管理员管理");
        JMenu userMenu=new JMenu("用户管理");
        JMenu SystemMenu=new JMenu("系统管理");
        menuBar.add(parentMenu);
        menuBar.add(adminMenu);
        menuBar.add(userMenu);
        menuBar.add(SystemMenu);
        //创建系统管理的二级菜单
        JMenuItem passwordMenu=new JMenuItem("修改密码");
        JMenuItem logoutMenu=new JMenuItem("退出登录");
        //二级菜单加入对应一级菜单中
        SystemMenu.add(passwordMenu);
        SystemMenu.add(logoutMenu);
        logoutMenu.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e){
                contentPanel.removeAll();
                contentPanel.repaint();
                MainFrame.setContent(new LoginPanel());
            }

        });
    }
    //切换窗口的功能,每一个功能都要提供一个内部窗口
    public static void setContent(JInternalFrame internalFrame){
        ///设置内部窗口的宽高
        internalFrame.setSize(SystemConstants.FRAME_WIDTH - 15,SystemConstants.FRAME_HEIGHT-60);
        internalFrame.setVisible(true);
        contentPanel.removeAll();
        contentPanel.repaint();
        contentPanel.add(internalFrame);

    }

}
